#pragma once

#include <atomic>
#include <functional>
#include <map>
#include <netinet/in.h>
#include <string>
#include <sys/socket.h>
#include <thread>
#include "net_endpoint.hpp"

namespace CG
{
  class UDPBackEnd
  {
  public:
    UDPBackEnd(NetEndPoint local);
    ~UDPBackEnd();
    bool Send(const unsigned char *const data, size_t length, const NetEndPoint &target);
    bool Receive(unsigned char *data, size_t bufferSize, ssize_t &length, NetEndPoint &source);

  private:
    int socketfd = -1;
    static bool SetSocketUnblock(int socketfd);
    static bool SetSocketAbleToBoardCast(int socketfd);
  };
} // namespace CG